//============================================================================================
/**
 * @file	friend_del_sublcd.c
 * @brief	友達手帳削除画面
 * @author	Hiroyuki Nakamura
 * @date	09.03.12
 */
//============================================================================================
#include "common.h"

#include "savedata/wifilist.h"
#include "system/lib_pack.h"
#include "system/snd_tool.h"
#include "system/fontproc.h"
#include "system/cursor_move.h"
#include "field/field.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_fieldmenu.h"

#include "../field_poketch.h"

#include "friend_del_sublcd.h"
#include "friend_del_snd_def.h"
#include "friend_del_gra.naix"


//============================================================================================
//	定数定義
//============================================================================================

#define HEAPID_SUBLCD_MENU	( HEAPID_POKETCH_APP )		// ヒープＩＤ

#define	FDD_SUB_ACTOR_DISTANCE 	( 256 * FX32_ONE )		// Ｙ座標オフセット
#define FDD_RES_TYPE_MAX		( 4 )					// リソースタイプ数
#define	FDD_RES_ID				( 1921 )				// リソースＩＤ

#define	FDD_SEL_NAME_MAX		( 8 )					// 表示名前数

// OBJ ID
enum {
	FDD_OBJ_CURSOR = 0,
	FDD_OBJ_RET_BUTTON,
	FDD_OBJ_ARROW_L,
	FDD_OBJ_ARROW_R,
	FDD_OBJ_MAX
};

// BMPWIN ID
enum {
	FDD_BMP_CANCEL = 0,
	FDD_BMP_PAGE,
	FDD_BMP_NAME01,
	FDD_BMP_NAME11 = FDD_BMP_NAME01 + FDD_SEL_NAME_MAX,
	FDD_BMP_MAX = FDD_BMP_NAME11 + FDD_SEL_NAME_MAX
};

// ボタンアニメＩＤ
enum {
	BTN_ANM_MODE_OBJ = 0,
	BTN_ANM_MODE_BG
};

// ボタンアニメワーク
typedef struct {
	u8	btn_mode:1;
	u8	btn_id:7;			// OBJ = ID, BG = FRM
	u8	btn_pal1:4;
	u8	btn_pal2:4;
	u8	btn_seq;
	u8	btn_cnt;

	u8	btn_px;			// BGのみ
	u8	btn_py;
	u8	btn_sx;
	u8	btn_sy;
}BUTTON_ANM_WORK;

typedef struct {
	// フィールドから渡されるもの
	GF_BGL_INI * bgl;
	u16 * sp_trg;
	FIELDSYS_WORK * fsys;
	void * scr_wk;

	TCB_PTR	tcb;	// 本体のポインタ

	WIFI_LIST * wlst;	// 友達手帳のセーブデータ

	CURSOR_MOVE_WORK * cmwk;	// カーソル移動ワーク

	BUTTON_ANM_WORK	bawk;

	GF_BGL_BMPWIN	win[FDD_BMP_MAX];	// BMPWIN

	MSGDATA_MANAGER * mman;
	WORDSET * wset;

	// セルアクター
	CLACT_SET_PTR 			claSet;						// セルアクターセット
	CLACT_U_EASYRENDER_DATA	rndDat;						// 簡易レンダーデータ
	CLACT_U_RES_MANAGER_PTR	resMan[FDD_RES_TYPE_MAX];	// リソースマネージャ
	CLACT_U_RES_OBJ_PTR 	resObj[FDD_RES_TYPE_MAX];	// リソースオブジェテーブル
	CLACT_WORK_PTR			actWork[FDD_OBJ_MAX];		// セルアクターワークポインタ配列

	u8	main_seq;
	u8	next_seq;
	s8	page;
	u8	swap;

	u32	push;
	u32 * ret;

}FDD_WORK;


// BMPWIN
//「やめる」
#define	BMPWIN_CANCEL_FRM	( GF_BGL_FRAME0_S )
#define	BMPWIN_CANCEL_PX	( 23 )
#define	BMPWIN_CANCEL_PY	( 21 )
#define	BMPWIN_CANCEL_SX	( 8 )
#define	BMPWIN_CANCEL_SY	( 2 )
#define	BMPWIN_CANCEL_PAL	( 2 )
#define	BMPWIN_CANCEL_CGX	( 1 )
// ページ数
#define	BMPWIN_PAGE_FRM		( GF_BGL_FRAME0_S )
#define	BMPWIN_PAGE_PX		( 14 )
#define	BMPWIN_PAGE_PY		( 21 )
#define	BMPWIN_PAGE_SX		( 4 )
#define	BMPWIN_PAGE_SY		( 2 )
#define	BMPWIN_PAGE_PAL		( 2 )
#define	BMPWIN_PAGE_CGX		( BMPWIN_CANCEL_CGX + BMPWIN_CANCEL_SX * BMPWIN_CANCEL_SY )
// 名前
#define	BMPWIN_NAME_FRM		( GF_BGL_FRAME0_S )
#define	BMPWIN_NAME_SX		( 10 )
#define	BMPWIN_NAME_SY		( 2 )
#define	BMPWIN_NAME_PAL		( 2 )
#define	BMPWIN_NAME_L_PX	( 3 )
#define	BMPWIN_NAME_R_PX	( 19 )
#define	BMPWIN_NAME_1_PY	( 1 )
#define	BMPWIN_NAME_2_PY	( 6 )
#define	BMPWIN_NAME_3_PY	( 11 )
#define	BMPWIN_NAME_4_PY	( 16 )
#define	BMPWIN_NAME_01_CGX	( BMPWIN_PAGE_CGX + BMPWIN_PAGE_SX * BMPWIN_PAGE_SY )
#define	BMPWIN_NAME_02_CGX	( BMPWIN_NAME_01_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_03_CGX	( BMPWIN_NAME_02_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_04_CGX	( BMPWIN_NAME_03_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_05_CGX	( BMPWIN_NAME_04_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_06_CGX	( BMPWIN_NAME_05_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_07_CGX	( BMPWIN_NAME_06_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_08_CGX	( BMPWIN_NAME_07_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_11_CGX	( BMPWIN_NAME_08_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_12_CGX	( BMPWIN_NAME_11_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_13_CGX	( BMPWIN_NAME_12_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_14_CGX	( BMPWIN_NAME_13_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_15_CGX	( BMPWIN_NAME_14_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_16_CGX	( BMPWIN_NAME_15_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_17_CGX	( BMPWIN_NAME_16_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
#define	BMPWIN_NAME_18_CGX	( BMPWIN_NAME_17_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )

// ボタンＩＤ
enum {
	BUTTON_ID_NAME1 = 0,
	BUTTON_ID_NAME2,
	BUTTON_ID_NAME3,
	BUTTON_ID_NAME4,
	BUTTON_ID_NAME5,
	BUTTON_ID_NAME6,
	BUTTON_ID_NAME7,
	BUTTON_ID_NAME8,
	BUTTON_ID_CANCEL,
};

// メインシーケンス
enum {
	MAINSEQ_MAIN = 0,
	MAINSEQ_BUTTON_ANM,
	MAINSEQ_PAGE_CHG,
	MAINSEQ_END
};


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
static void VramInit(void);
static void BgInit( GF_BGL_INI * bgl );
static void BgExit( GF_BGL_INI * bgl );
static void BgGraLoad( FDD_WORK * wk, ARCHANDLE * ah );
static void MsgInit( FDD_WORK * wk );
static void MsgExit( FDD_WORK * wk );
static void BmpInit( FDD_WORK * wk );
static void BmpExit( FDD_WORK * wk );
static void PageNumPut( FDD_WORK * wk );
static void NamePut( FDD_WORK * wk );
static void ObjInit( FDD_WORK * wk, ARCHANDLE * ah );
static void ObjExit( FDD_WORK * wk );
static void ClaResManInit( FDD_WORK * wk );
static void ClaResManExit( FDD_WORK * wk );
static void ClaAdd( FDD_WORK * wk, ARCHANDLE * ah );
static void ClaDel( FDD_WORK * wk );
static void CursorMoveInit( FDD_WORK * wk );
static void CursorMoveExit( FDD_WORK * wk );
static void CursorMoveCallBack_On( void * work, int now_pos, int old_pos );
static void CursorMoveCallBack_Move( void * work, int now_pos, int old_pos );

static void MainTask( TCB_PTR tcb, void * work );
static u8 MainSeq_Main( FDD_WORK * wk );
static u8 MainSeq_ButtonAnm( FDD_WORK * wk );
static u8 PageChange( FDD_WORK * wk, s8 mv );

static BOOL ButtonAnmMain( FDD_WORK * wk );
static u8 ObjButtonAnmSet( FDD_WORK * wk, u8 id, u8 anm1, u8 anm2, u8 next );
static u8 BgButtonAnmSet( FDD_WORK * wk, u8 px, u8 py, u8 next );


//============================================================================================
//	グローバル変数
//============================================================================================

// BMPWIN
static const BMPWIN_DAT BmpWinData[] =
{
	{	//「やめる」
		BMPWIN_CANCEL_FRM, BMPWIN_CANCEL_PX, BMPWIN_CANCEL_PY,
		BMPWIN_CANCEL_SX, BMPWIN_CANCEL_SY, BMPWIN_CANCEL_PAL, BMPWIN_CANCEL_CGX
	},
	{	// ページ数
		BMPWIN_PAGE_FRM, BMPWIN_PAGE_PX, BMPWIN_PAGE_PY,
		BMPWIN_PAGE_SX, BMPWIN_PAGE_SY, BMPWIN_PAGE_PAL, BMPWIN_PAGE_CGX
	},

	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_1_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_01_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_1_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_02_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_2_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_03_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_2_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_04_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_3_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_05_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_3_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_06_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_4_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_07_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_4_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_08_CGX
	},

	// スワップ
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_1_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_11_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_1_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_12_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_2_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_13_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_2_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_14_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_3_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_15_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_3_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_16_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_L_PX, BMPWIN_NAME_4_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_17_CGX
	},
	{	// 名前
		BMPWIN_NAME_FRM, BMPWIN_NAME_R_PX, BMPWIN_NAME_4_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_18_CGX
	},
};

// タッチデータ
static const RECT_HIT_TBL RectHitTbl[] =
{
	{   8,  23,  24, 103 },		// 00: 0
	{   8,  23, 152, 231 },		// 01: 1
	{  48,  63,  24, 103 },		// 02: 2
	{  48,  63, 152, 231 },		// 03: 3
	{  88, 103,  24, 103 },		// 04: 4
	{  88, 103, 152, 231 },		// 05: 5
	{ 128, 143,  24, 103 },		// 06: 6
	{ 128, 143, 152, 231 },		// 07: 7

	{ 160, 191, 176, 255 },		// 08: やめる

	{ RECT_HIT_END, 0, 0, 0 }
};
static const POINTER_WORK KeyTbl[] =
{
	{  64,  16, 0, 0,	0, 2, 0, 1 },		// 00: 0
	{ 192,  16, 0, 0,	1, 3, 0, 1 },		// 01: 1
	{  64,  56, 0, 0,	0, 4, 2, 3 },		// 02: 2
	{ 192,  56, 0, 0,	1, 5, 2, 3 },		// 03: 3
	{  64,  96, 0, 0,	2, 6, 4, 5 },		// 04: 4
	{ 192,  96, 0, 0,	3, 7, 4, 5 },		// 05: 5
	{  64, 136, 0, 0,	4, 8, 6, 7 },		// 06: 6
	{ 192, 136, 0, 0,	5, 8, 6, 7 },		// 07: 7

	{ 216, 176, 0, 0,	CURSORMOVE_RETBIT|7, 8, 8, 8 },	// 08: やめる
};
static const CURSORMOVE_CALLBACK CursorMoveCallBack = {
	CursorMoveCallBack_On,
	CursorMoveCallBack_On,
	CursorMoveCallBack_Move,
	CursorMoveCallBack_Move
};




//--------------------------------------------------------------------------------------------
/**
 * 初期化
 *
 * @param	bgl
 * @param	sub_panel_trg
 * @param	fsys
 * @param	work
 *
 * @return	TCB_PTR
 */
//--------------------------------------------------------------------------------------------
TCB_PTR FriendDelSublcdInit(
			GF_BGL_INI * bgl, u16 * sub_panel_trg, FIELDSYS_WORK * fsys, void * work )
{
	TCB_PTR	tcb;
	FDD_WORK * wk;
	ARCHANDLE * ah;

	// 異様にデカいがポケッチの合計と同じにしておく
	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_SUBLCD_MENU,  0x18000 );

	G2S_BlendNone();

	tcb = PMDS_taskAdd( MainTask, sizeof(FDD_WORK), 10, HEAPID_SUBLCD_MENU );
	wk  = TCB_GetWork( tcb );

	wk->bgl    = bgl;
	wk->sp_trg = sub_panel_trg;
	wk->fsys   = fsys;
	wk->scr_wk = work;
	wk->tcb    = tcb;
	wk->wlst   = SaveData_GetWifiListData( fsys->savedata );
	wk->ret    = work;

	*wk->ret = FRIEND_DEL_SUBLCD_RET_NONE;

	// タッチフォント読み込み
	FontProc_LoadFont( FONT_TOUCH, HEAPID_SUBLCD_MENU );

	ah = ArchiveDataHandleOpen( ARC_FRIEND_DEL_GRA, HEAPID_SUBLCD_MENU );

	VramInit();
	BgInit( bgl );
	BgGraLoad( wk, ah );
	MsgInit( wk );
	BmpInit( wk );
	ObjInit( wk, ah );
	CursorMoveInit( wk );

	ArchiveDataHandleClose( ah );

	return tcb;
}

//--------------------------------------------------------------------------------------------
/**
 * 終了リクエスト
 *
 * @param	bgl		GF_BGL_INI
 * @param	tcb		TCB_PTR
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void FriendDelSublcdQuitReq( GF_BGL_INI * bgl,  TCB_PTR tcb )
{
	FDD_WORK * wk = TCB_GetWork( tcb );

	CursorMoveExit( wk );
	ObjExit( wk );
	BmpExit( wk );
	MsgExit( wk );
	BgExit( wk->bgl );

	FontProc_UnloadFont( FONT_TOUCH );

	// タスク消去
	PMDS_taskDel( tcb );

	sys_DeleteHeap( HEAPID_SUBLCD_MENU );
}

//--------------------------------------------------------------------------------------------
/**
 * 終了待ち
 *
 * @param	bgl		GF_BGL_INI
 *
 * @retval	"TRUE = 終了"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
BOOL FriendDelSublcdQuitWait( GF_BGL_INI * bgl )
{
	return TRUE;
}

//--------------------------------------------------------------------------------------------
/**
 * VRAM初期化
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void VramInit(void)
{
	GX_SetBankForSubBG( GX_VRAM_SUB_BG_32_H );
	GX_SetBankForSubOBJ( GX_VRAM_SUB_OBJ_16_I );
	GXS_SetOBJVRamModeChar( GX_OBJVRAMMODE_CHAR_1D_32K );
}

//--------------------------------------------------------------------------------------------
/**
 * BG初期化
 *
 * @param	bgl		GF_BGL_INI
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgInit( GF_BGL_INI * bgl )
{
	GXS_SetGraphicsMode( GX_BGMODE_0 );

	{
		GF_BGL_BGCNT_HEADER head = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x7800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( bgl, GF_BGL_FRAME0_S, &head, GF_BGL_MODE_TEXT );
		GF_BGL_ClearCharSet( GF_BGL_FRAME0_S, 32, 0, HEAPID_SUBLCD_MENU );
		GF_BGL_ScrClear( bgl, GF_BGL_FRAME0_S );
	}
	{
		GF_BGL_BGCNT_HEADER head = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x7000, GX_BG_CHARBASE_0x04000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( bgl, GF_BGL_FRAME1_S, &head, GF_BGL_MODE_TEXT );
	}
	{
		GF_BGL_BGCNT_HEADER head = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x6800, GX_BG_CHARBASE_0x04000, GX_BG_EXTPLTT_01,
			2, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( bgl, GF_BGL_FRAME2_S, &head, GF_BGL_MODE_TEXT );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * BG解放
 *
 * @param	bgl		GF_BGL_INI
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgExit( GF_BGL_INI * bgl )
{
	GF_BGL_BGControlExit( bgl, GF_BGL_FRAME2_S );
	GF_BGL_BGControlExit( bgl, GF_BGL_FRAME1_S );
	GF_BGL_BGControlExit( bgl, GF_BGL_FRAME0_S );
}

//--------------------------------------------------------------------------------------------
/**
 * BGグラフィックロード
 *
 * @param	wk		友達手帳削除画面ワーク
 * @param	ah		アークハンドル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgGraLoad( FDD_WORK * wk, ARCHANDLE * ah )
{
	ArcUtil_HDL_BgCharSet(
		ah, NARC_friend_del_gra_f_del_bg_lz_NCGR,
		wk->bgl, GF_BGL_FRAME1_S, 0, 0, TRUE, HEAPID_SUBLCD_MENU );

	ArcUtil_HDL_ScrnSet(
		ah, NARC_friend_del_gra_f_del_bg2_lz_NSCR,
		wk->bgl, GF_BGL_FRAME1_S, 0, 0, TRUE, HEAPID_SUBLCD_MENU );
	ArcUtil_HDL_ScrnSet(
		ah, NARC_friend_del_gra_f_del_bg1_lz_NSCR,
		wk->bgl, GF_BGL_FRAME2_S, 0, 0, TRUE, HEAPID_SUBLCD_MENU );

	ArcUtil_HDL_PalSet(
		ah, NARC_friend_del_gra_f_del_bg_NCLR, PALTYPE_SUB_BG, 0, 0, HEAPID_SUBLCD_MENU );
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージ関連初期化
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MsgInit( FDD_WORK * wk )
{
	wk->mman = MSGMAN_Create(
						MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_fieldmenu_dat, HEAPID_SUBLCD_MENU );
	wk->wset = WORDSET_Create( HEAPID_SUBLCD_MENU );
//	appwk->expbuf = STRBUF_Create( EXP_BUF_SIZE, HEAPID_MAILBOX_APP );
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージ関連解放
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MsgExit( FDD_WORK * wk )
{
//	STRBUF_Delete( appwk->expbuf );
	WORDSET_Delete( wk->wset );
	MSGMAN_Delete( wk->mman );
}

//--------------------------------------------------------------------------------------------
/**
 * BMP初期化
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BmpInit( FDD_WORK * wk )
{
	STRBUF * str;
	u16	i;
	u16	px;

	for( i=0; i<FDD_BMP_MAX; i++ ){
		GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &BmpWinData[i] );
	}

	//「やめる」
	GF_BGL_BmpWinDataFill( &wk->win[FDD_BMP_CANCEL], 0 );
	str = MSGMAN_AllocString( wk->mman, msg_menu_29 );
	px  = GF_BGL_BmpWinGet_SizeX( &wk->win[FDD_BMP_CANCEL] ) * 8 / 2;
	px -= ( FontProc_GetPrintStrWidth( FONT_TOUCH, str, 0 ) / 2 );
	GF_STR_PrintColor(
		&wk->win[FDD_BMP_CANCEL], FONT_TOUCH, str, px, 0,
		MSG_NO_PUT, GF_PRINTCOLOR_MAKE(5,6,0), NULL );
	STRBUF_Delete( str );
	GF_BGL_BmpWinCgxOn( &wk->win[FDD_BMP_CANCEL] );
	GF_BGL_BmpWinOnVReq( &wk->win[FDD_BMP_CANCEL] );

	// ページ数
	PageNumPut( wk );

	// 名前表示
	NamePut( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * BMP解放
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BmpExit( FDD_WORK * wk )
{
	u32	i;

	for( i=0; i<FDD_BMP_MAX; i++ ){
		GF_BGL_BmpWinDel( &wk->win[i] );
	}
}


//--------------------------------------------------------------------------------------------
/**
 * ページ数表示
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PageNumPut( FDD_WORK * wk )
{
	STRBUF * exp;
	STRBUF * str;
	u16	px, ssx;

	GF_BGL_BmpWinDataFill( &wk->win[FDD_BMP_PAGE], 0 );

	// ／
	str = MSGMAN_AllocString( wk->mman, msg_menu_28 );
	ssx = FontProc_GetPrintStrWidth( FONT_SYSTEM, str, 0 );
	px  = ( GF_BGL_BmpWinGet_SizeX( &wk->win[FDD_BMP_PAGE] ) * 8 - ssx ) / 2;
	GF_STR_PrintColor(
		&wk->win[FDD_BMP_PAGE], FONT_SYSTEM, str, px, 0,
		MSG_NO_PUT, GF_PRINTCOLOR_MAKE(5,6,0), NULL );
	STRBUF_Delete( str );

	exp = STRBUF_Create( 4, HEAPID_SUBLCD_MENU );

	// 最大ページ数
	str = MSGMAN_AllocString( wk->mman, msg_menu_27 );
	WORDSET_RegisterNumber( wk->wset, 0, 4, 1, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, exp, str );
	GF_STR_PrintColor(
		&wk->win[FDD_BMP_PAGE], FONT_SYSTEM, exp, px+ssx, 0,
		MSG_NO_PUT, GF_PRINTCOLOR_MAKE(5,6,0), NULL );
	STRBUF_Delete( str );

	// 現在のページ数
	str = MSGMAN_AllocString( wk->mman, msg_menu_27 );
	WORDSET_RegisterNumber( wk->wset, 0, wk->page+1, 1, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, exp, str );
	px -= FontProc_GetPrintStrWidth( FONT_SYSTEM, exp, 0 );
	GF_STR_PrintColor(
		&wk->win[FDD_BMP_PAGE], FONT_SYSTEM, exp, px, 0,
		MSG_NO_PUT, GF_PRINTCOLOR_MAKE(5,6,0), NULL );
	STRBUF_Delete( str );

	STRBUF_Delete( exp );

	GF_BGL_BmpWinCgxOn( &wk->win[FDD_BMP_PAGE] );
	GF_BGL_BmpWinOnVReq( &wk->win[FDD_BMP_PAGE] );
}

//--------------------------------------------------------------------------------------------
/**
 * 名前表示
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void NamePut( FDD_WORK * wk )
{
	MYSTATUS * myst;
	GF_BGL_BMPWIN * win;
	STRBUF * str;
	STRBUF * exp;
	u16	wpx;
	u16	i;

	if( wk->swap == 0 ){
		win = &wk->win[FDD_BMP_NAME01];
	}else{
		win = &wk->win[FDD_BMP_NAME11];
	}

	str  = MSGMAN_AllocString( wk->mman, msg_menu_30 );
	exp  = STRBUF_Create( 64, HEAPID_SUBLCD_MENU );
	myst = MyStatus_AllocWork( HEAPID_SUBLCD_MENU );
	wpx  = GF_BGL_BmpWinGet_SizeX( win ) * 8 / 2;

	for( i=0; i<FDD_SEL_NAME_MAX; i++ ){
		MyStatus_SetMyName( myst, WifiList_GetFriendNamePtr( wk->wlst, wk->page*FDD_SEL_NAME_MAX+i ) );
		WORDSET_RegisterPlayerName( wk->wset, 0, myst );
		WORDSET_ExpandStr( wk->wset, exp, str );

		GF_BGL_BmpWinDataFill( &win[i], 0 );
		GF_STR_PrintColor(
			&win[i], FONT_TOUCH, exp,
			wpx - FontProc_GetPrintStrWidth(FONT_SYSTEM,exp,0) / 2,
			0,
			MSG_NO_PUT, GF_PRINTCOLOR_MAKE(5,6,0), NULL );
		GF_BGL_BmpWinCgxOn( &win[i] );
		GF_BGL_BmpWinOnVReq( &win[i] );
	}

	sys_FreeMemoryEz( myst );
	STRBUF_Delete( exp );
	STRBUF_Delete( str );

	wk->swap ^= 1;
}

//--------------------------------------------------------------------------------------------
/**
 * OBJ初期化
 *
 * @param	wk		友達手帳削除画面ワーク
 * @param	ah		アークハンドル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjInit( FDD_WORK * wk, ARCHANDLE * ah )
{
	// セルアクター初期化
	wk->claSet = CLACT_U_SetEasyInit( FDD_OBJ_MAX, &wk->rndDat, HEAPID_SUBLCD_MENU );

	CLACT_U_SetSubSurfaceMatrix( &wk->rndDat, 0, FDD_SUB_ACTOR_DISTANCE );

	ClaResManInit( wk );

	ClaAdd( wk, ah );
}

//--------------------------------------------------------------------------------------------
/**
 * OBJ解放
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjExit( FDD_WORK * wk )
{
	ClaDel( wk );

	ClaResManExit( wk );
	CLACT_DestSet( wk->claSet );
}

//--------------------------------------------------------------------------------------------
/**
 * リソースマネージャー初期化
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaResManInit( FDD_WORK * wk )
{
	u32	i;

	for( i=0; i<FDD_RES_TYPE_MAX; i++ ){
		wk->resMan[i] = CLACT_U_ResManagerInit( 1, i, HEAPID_SUBLCD_MENU );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リソースマネージャ削除
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaResManExit( FDD_WORK * wk )
{
	u32	i;

	for( i=0; i<FDD_RES_TYPE_MAX; i++ ){
		CLACT_U_ResManagerDelete( wk->resMan[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リソース読み込み
 *
 * @param	res_obj			リソースオブジェ
 * @param	res_man			リソースマネージャ
 * @param	ah				アークハンドル
 * @param	chr				キャラクタデータインデックス
 * @param	pal				パレットデータインデックス
 * @param	cel				セルデータインデックス
 * @param	anm				セルアニメインデックス
 * @param	pal_max			パレット数
 * @param	comm_res_chr	キャラリソースＩＤ
 * @param	comm_res_pal	パレットリソースＩＤ
 * @param	comm_res_cel	セルリソースＩＤ
 * @param	comm_res_anm	アニメリソースＩＤ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaResLoadHandle(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man,
				ARCHANDLE * ah,
				int chr,
				int pal,
				int cel,
				int anm,
				int pal_max,
				int comm_res_chr,
				int comm_res_pal,
				int comm_res_cel,
				int comm_res_anm )
{
	// キャラクタデータ読み込み
	res_obj[CLACT_U_CHAR_RES] = CLACT_U_ResManagerResAddArcChar_ArcHandle(
									res_man[CLACT_U_CHAR_RES],
									ah,
									chr,
									TRUE,
									comm_res_chr,
									NNS_G2D_VRAM_TYPE_2DSUB,
									HEAPID_SUBLCD_MENU );

	// 転送
	CLACT_U_CharManagerSetAreaCont( res_obj[CLACT_U_CHAR_RES] );
	// グラフィックデータだけ破棄
	CLACT_U_ResManagerResOnlyDelete( res_obj[CLACT_U_CHAR_RES] );

	// パレットデータ読み込み
	res_obj[CLACT_U_PLTT_RES] = CLACT_U_ResManagerResAddArcPltt_ArcHandle(
									res_man[CLACT_U_PLTT_RES],
									ah,
									pal,
									FALSE,
									comm_res_pal,
									NNS_G2D_VRAM_TYPE_2DSUB,
									pal_max,
									HEAPID_SUBLCD_MENU );
	// 転送
	CLACT_U_PlttManagerSetCleanArea( res_obj[CLACT_U_PLTT_RES] );
	// グラフィックデータだけ破棄
	CLACT_U_ResManagerResOnlyDelete( res_obj[CLACT_U_PLTT_RES] );

	// セルデータ読み込み
	res_obj[CLACT_U_CELL_RES] = CLACT_U_ResManagerResAddArcKindCell_ArcHandle(
									res_man[CLACT_U_CELL_RES],
									ah,
									cel,
									TRUE,
									comm_res_cel,
									CLACT_U_CELL_RES,
									HEAPID_SUBLCD_MENU );

	// セルアニメデータ読み込み
	res_obj[CLACT_U_CELLANM_RES] = CLACT_U_ResManagerResAddArcKindCell_ArcHandle(
									res_man[CLACT_U_CELLANM_RES],
									ah,
									anm,
									TRUE,
									comm_res_anm,
									CLACT_U_CELLANM_RES,
									HEAPID_SUBLCD_MENU );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターヘッダー作成
 *
 * @param	res_obj		リソースオブジェ
 * @param	res_man		リソースマネージャー
 * @param	head		ヘッダー作成先
 * @param	bg_pri		ＢＧとのプライオリティ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaHeaderMake(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man,
				CLACT_HEADER * head,
				int bg_pri )
{
	CLACT_U_MakeHeader(
		head,
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CHAR_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_PLTT_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CELL_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CELLANM_RES] ),
		CLACT_U_HEADER_DATA_NONE,
		CLACT_U_HEADER_DATA_NONE,
		0,
		bg_pri,
		res_man[CLACT_U_CHAR_RES],
		res_man[CLACT_U_PLTT_RES],
		res_man[CLACT_U_CELL_RES],
		res_man[CLACT_U_CELLANM_RES],
		NULL,
		NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクター追加
 *
 * @param	wk			友達手帳削除画面ワーク
 * @param	objID		OBJ ID
 * @param	hed			ヘッダー
 * @param	prm			OBJ表示パラメータ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaAddCore( FDD_WORK * wk, u32 objID, CLACT_HEADER * hed, const u8 * prm )
{
	CLACT_ADD add;

	add.ClActSet    = wk->claSet;
	add.ClActHeader = hed;

	add.mat.x       = (prm[0]<<FX32_SHIFT);
	add.mat.y       = (prm[1]<<FX32_SHIFT) + FDD_SUB_ACTOR_DISTANCE;
	add.mat.z       = 0;

	add.sca.x       = FX32_ONE;
	add.sca.y       = FX32_ONE;
	add.sca.z       = FX32_ONE;

	add.rot         = 0;
	add.pri         = prm[2];
	add.DrawArea    = NNS_G2D_VRAM_TYPE_2DSUB;
	add.heap        = HEAPID_SUBLCD_MENU;

	wk->actWork[objID] = CLACT_Add( &add );

	CLACT_AnmChg( wk->actWork[objID], prm[3] );
}

// ＯＢＪデータ
static const u8 ObjParam[][4] =
{	// x, y, pri, anm
	{  32,  32, 0, 0 },	// カーソル
	{ 216, 176, 1, 2 },	// やめる
	{  24, 176, 1, 4 },	// 左矢印
	{  56, 176, 1, 6 },	// 右矢印
};

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪを追加
 *
 * @param	wk		友達手帳削除画面ワーク
 * @param	ah		アークハンドル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaAdd( FDD_WORK * wk, ARCHANDLE * ah )
{
	CLACT_HEADER	hed;
	u32	i;

	ClaResLoadHandle(
		wk->resObj,
		wk->resMan,
		ah,
		NARC_friend_del_gra_f_del_obj_lz_NCGR,
		NARC_friend_del_gra_f_del_obj_NCLR,
		NARC_friend_del_gra_f_del_obj_lz_NCER,
		NARC_friend_del_gra_f_del_obj_lz_NANR,
		1,
		FDD_RES_ID,
		FDD_RES_ID,
		FDD_RES_ID,
		FDD_RES_ID );

	ClaHeaderMake( wk->resObj, wk->resMan, &hed, 1 );

	for( i=0; i<FDD_OBJ_MAX; i++ ){
		ClaAddCore( wk, i, &hed, ObjParam[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪを削除
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaDel( FDD_WORK * wk )
{
	u32	i;

	for( i=0; i<FDD_OBJ_MAX; i++ ){
		CLACT_Delete( wk->actWork[i] );
	}

	CLACT_U_CharManagerDelete( wk->resObj[CLACT_U_CHAR_RES] );
	CLACT_U_PlttManagerDelete( wk->resObj[CLACT_U_PLTT_RES] );
}

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪアニメメイン
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaAnmMain( FDD_WORK * wk )
{
	u32	i;

	for( i=0; i<FDD_OBJ_MAX; i++ ){
		CLACT_AnmFrameChg( wk->actWork[i], FX32_ONE );
	}
}


//--------------------------------------------------------------------------------------------
/**
 * カーソル表示
 *
 * @param	wk		友達手帳削除画面ワーク
 * @param	pos		位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorObjPut( FDD_WORK * wk, u32 pos )
{
	const POINTER_WORK * pw;
	VecFx32	vec;

	pw = CURSORMOVE_PointerWorkGet( wk->cmwk, pos );

	vec.x = pw->px * FX32_ONE;
	vec.y = pw->py * FX32_ONE + FDD_SUB_ACTOR_DISTANCE;

	CLACT_SetMatrix( wk->actWork[FDD_OBJ_CURSOR], &vec );

	if( pos == BUTTON_ID_CANCEL ){
		CLACT_AnmChg( wk->actWork[FDD_OBJ_CURSOR], 1 );
	}else{
		CLACT_AnmChg( wk->actWork[FDD_OBJ_CURSOR], 0 );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * カーソル移動初期化
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorMoveInit( FDD_WORK * wk )
{
	wk->cmwk = CURSORMOVE_Create(
					RectHitTbl,
					KeyTbl,
					&CursorMoveCallBack,
					wk,
					TRUE,
					0,
					HEAPID_SUBLCD_MENU );

	CursorObjPut( wk, 0 );
}

//--------------------------------------------------------------------------------------------
/**
 * カーソル移動削除
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorMoveExit( FDD_WORK * wk )
{
	CURSORMOVE_Exit( wk->cmwk );
}

//--------------------------------------------------------------------------------------------
/**
 * カーソル移動コールバック関数：ダミー
 *
 * @param	work		友達手帳削除画面ワーク
 * @param	now_pos		現在の位置
 * @param	old_pos		前回の位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorMoveCallBack_On( void * work, int now_pos, int old_pos )
{
}

//--------------------------------------------------------------------------------------------
/**
 * カーソル移動コールバック関数：カーソル移動時（タッチも）
 *
 * @param	work		友達手帳削除画面ワーク
 * @param	now_pos		現在の位置
 * @param	old_pos		前回の位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorMoveCallBack_Move( void * work, int now_pos, int old_pos )
{
	FDD_WORK * wk = work;

	CursorObjPut( wk, now_pos );
}


//--------------------------------------------------------------------------------------------
/**
 * メインタスク
 *
 * @param	tcb		TCB_PTR
 * @param	wk		ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MainTask( TCB_PTR tcb, void * work )
{
	FDD_WORK * wk = work;

	switch( wk->main_seq ){
	case MAINSEQ_MAIN:
		wk->main_seq = MainSeq_Main( wk );
		break;

	case MAINSEQ_BUTTON_ANM:
		wk->main_seq = MainSeq_ButtonAnm( wk );
		break;

	case MAINSEQ_PAGE_CHG:
		PageNumPut( wk );	// ページ数
		NamePut( wk );		// 名前表示
		wk->main_seq = MAINSEQ_MAIN;
		break;

	case MAINSEQ_END:
		*wk->ret = wk->push;
		break;
	}

	ClaAnmMain( wk );
	CLACT_Draw( wk->claSet );
}


// メール選択ページ切り替え
static const RECT_HIT_TBL ArrowHitTbl[] =
{
	{ 160, 191,   8,  39 },		// 0: 左矢印
	{ 160, 191,  40,  71 },		// 1: 右矢印
	{ RECT_HIT_END, 0, 0, 0 }
};

// 名前ボタン表示データ
#define	NAME_BUTTON_POS_X	( 2 )
#define	NAME_BUTTON_POS_Y	( 0 )
#define	NAME_BUTTON_SPC_X	( 16 )
#define	NAME_BUTTON_SPC_Y	( 5 )
#define	NAME_BUTTON_SX		( 12 )
#define	NAME_BUTTON_SY		( 4 )


//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：メイン
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 MainSeq_Main( FDD_WORK * wk )
{
	u32	ret;

	// ページ切り替え矢印タッチチェック
	ret = GF_TP_RectHitTrg( ArrowHitTbl );
	// 左矢印
	if( ret == 0 ){
		Snd_SePlay( SE_FDD_SCROLL_TOUCH );
		return PageChange( wk, -1 );
	// 右矢印
	}else if( ret == 1 ){
		Snd_SePlay( SE_FDD_SCROLL_TOUCH );
		return PageChange( wk, 1 );
	}

	ret = CURSORMOVE_MainCont( wk->cmwk );

	switch( ret ){
	case BUTTON_ID_NAME1:
	case BUTTON_ID_NAME2:
	case BUTTON_ID_NAME3:
	case BUTTON_ID_NAME4:
	case BUTTON_ID_NAME5:
	case BUTTON_ID_NAME6:
	case BUTTON_ID_NAME7:
	case BUTTON_ID_NAME8:
		Snd_SePlay( SE_FDD_SELECT );
		wk->push = wk->page * FDD_SEL_NAME_MAX + ret;
		return BgButtonAnmSet(
					wk,
					NAME_BUTTON_POS_X+(NAME_BUTTON_SPC_X*(ret&1)),
					NAME_BUTTON_POS_Y+(NAME_BUTTON_SPC_Y*(ret>>1)),
					MAINSEQ_END );


	case BUTTON_ID_CANCEL:		//「やめる」
	case CURSORMOVE_CANCEL:		// キャンセル
		Snd_SePlay( SE_FDD_CANCEL );
		wk->push = FRIEND_DEL_SUBLCD_RET_CANCEL;
		return ObjButtonAnmSet( wk, FDD_OBJ_RET_BUTTON, 3, 2, MAINSEQ_END );

	case CURSORMOVE_NONE:			// 動作なし
		{
			u8	pos = CURSORMOVE_PosGet( wk->cmwk );
			if( sys.repeat & PAD_KEY_RIGHT ){
				if( pos == BUTTON_ID_NAME2 || pos == BUTTON_ID_NAME4 ||
					pos == BUTTON_ID_NAME6 || pos == BUTTON_ID_NAME8 ){
					Snd_SePlay( SE_FDD_SCROLL_KEY );
					return PageChange( wk, 1 );
				}
			}
			if( sys.repeat & PAD_KEY_LEFT ){
				if( pos == BUTTON_ID_NAME1 || pos == BUTTON_ID_NAME3 ||
					pos == BUTTON_ID_NAME5 || pos == BUTTON_ID_NAME7 ){
					Snd_SePlay( SE_FDD_SCROLL_KEY );
					return PageChange( wk, -1 );
				}
			}
		}
		break;

	case CURSORMOVE_CURSOR_ON:		// カーソル表示
		break;

	case CURSORMOVE_CURSOR_MOVE:	// 移動
		Snd_SePlay( SE_FDD_MOVE );
		break;
	}

	return MAINSEQ_MAIN;
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：ボタン切り替え
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 MainSeq_ButtonAnm( FDD_WORK * wk )
{
	if( ButtonAnmMain( wk ) == FALSE ){
		return wk->next_seq;
	}
	return MAINSEQ_BUTTON_ANM;
}

static u8 PageChange( FDD_WORK * wk, s8 mv )
{
	u16	id;
	u16	anm;

	wk->page += mv;
	if( wk->page < 0 ){
		wk->page = 3;
	}
	if( wk->page > 3 ){
		wk->page = 0;
	}

	if( mv > 0 ){
		id  = FDD_OBJ_ARROW_R;
		anm = 6;
	}else{
		id  = FDD_OBJ_ARROW_L;
		anm = 4;
	}

	return ObjButtonAnmSet( wk, id, anm+1, anm, MAINSEQ_PAGE_CHG );
}

//--------------------------------------------------------------------------------------------
/**
 * ボタン切り替え
 *
 * @param	wk		友達手帳削除画面ワーク
 * @param	pal		パレット
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ButtonAnmCore( FDD_WORK * wk, u8 pal )
{
	if( wk->bawk.btn_mode == BTN_ANM_MODE_OBJ ){
		CLACT_AnmChg( wk->actWork[wk->bawk.btn_id], pal );
	}else{
		GF_BGL_ScrPalChange(
			wk->bgl, wk->bawk.btn_id,
			wk->bawk.btn_px, wk->bawk.btn_py, wk->bawk.btn_sx, wk->bawk.btn_sy, pal );
		GF_BGL_LoadScreenV_Req( wk->bgl, wk->bawk.btn_id );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ボタンアニメ処理
 *
 * @param	wk		友達手帳削除画面ワーク
 *
 * @retval	"TRUE = アニメ中"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
static BOOL ButtonAnmMain( FDD_WORK * wk )
{
	BUTTON_ANM_WORK * bawk = &wk->bawk;

	switch( bawk->btn_seq ){
	case 0:
		ButtonAnmCore( wk, bawk->btn_pal1 );
		bawk->btn_seq++;
		break;

	case 1:
		bawk->btn_cnt++;
		if( bawk->btn_cnt != 4 ){ break; }
		ButtonAnmCore( wk, bawk->btn_pal2 );
		bawk->btn_cnt = 0;
		bawk->btn_seq++;
		break;

	case 2:
		bawk->btn_cnt++;
		if( bawk->btn_cnt == 2 ){
			return FALSE;
		}
	}

	return TRUE;
}

//--------------------------------------------------------------------------------------------
/**
 * ボタンアニメ設定（ＯＢＪ）
 *
 * @param	wk		友達手帳削除画面ワーク
 * @param	id		OBJ ID
 * @param	anm1	アニメ１
 * @param	anm2	アニメ２
 * @param	next	アニメ後に移行するシーケンス
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ObjButtonAnmSet( FDD_WORK * wk, u8 id, u8 anm1, u8 anm2, u8 next )
{
	wk->bawk.btn_mode = BTN_ANM_MODE_OBJ;
	wk->bawk.btn_cnt  = 0;
	wk->bawk.btn_seq  = 0;
	wk->bawk.btn_id   = id;
	wk->bawk.btn_pal1 = anm1;
	wk->bawk.btn_pal2 = anm2;

	wk->next_seq = next;
	return MAINSEQ_BUTTON_ANM;
}

//--------------------------------------------------------------------------------------------
/**
 * ボタンアニメ設定（ＢＧ）
 *
 * @param	wk		友達手帳削除画面ワーク
 * @param	px		Ｘ座標
 * @param	py		Ｘ座標
 * @param	next	アニメ後に移行するシーケンス
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 BgButtonAnmSet( FDD_WORK * wk, u8 px, u8 py, u8 next )
{
	wk->bawk.btn_mode = BTN_ANM_MODE_BG;
	wk->bawk.btn_cnt  = 0;
	wk->bawk.btn_seq  = 0;
	wk->bawk.btn_id   = GF_BGL_FRAME1_S;
	wk->bawk.btn_pal1 = 1;
	wk->bawk.btn_pal2 = 0;

	wk->bawk.btn_px = px;
	wk->bawk.btn_py = py;
	wk->bawk.btn_sx = NAME_BUTTON_SX;
	wk->bawk.btn_sy = NAME_BUTTON_SY;

	wk->next_seq = next;
	return MAINSEQ_BUTTON_ANM;
}